package com.ids.actions;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.ids.bean.UserInfo;
import com.ids.service.LoginService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


public class ChangePassword extends ActionSupport {


	private static final long serialVersionUID = 1L;
	private String userName;
	private String password;
	private String newPassword;
	private String confirmPassword;

	public String execute() throws Exception {

		boolean forward = false;
		HttpServletRequest request = ServletActionContext.getRequest();
		if (confirmPassword.equals(newPassword)) {
		Map<String, Object> session = ActionContext.getContext().getSession();
		UserInfo userInfo = (UserInfo) session.get("userInfo");
		LoginService loginService = new LoginService();
		forward = loginService.changePassword(userInfo.getEmpCode(),password, newPassword);
		}
		if (!forward) {
			request.setAttribute("ChangePasswordMessage","Failure in changing password");
			return ERROR;
		}
		request.setAttribute("ChangePasswordMessage","Password has been changed successfully");
		return SUCCESS;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	public String getConfirmPassword() {
		return confirmPassword;
	}

	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

}
